{%- include reset/workdir.liquid %}

{% comment %} display the directory name {% endcomment %}
{%- assign dir = site_pages | where: "url", workdir | first -%}
{%- if site_lang != lang -%}
    {% comment %} current in language directory (level-1) {% endcomment %}
    {%- assign workdir_level = workdir_level | minus: 1 -%}
{%- endif -%}
{%- if workdir_level == 2 %}
    {% comment %} display the root sub-directory as "p.caption" {% endcomment %}
    <p class="caption"><span class="caption-text">{{ dir.title | default: dir.url }}</span></p>
{%- else %}
    <a class="reference internal" href="{{ dir.url | relative_url }}">{{ dir.title | default: dir.url }}</a>
{%- endif -%}

<ul>
    {% comment %} list file {% endcomment %}
    {%- for item in workdir_files -%}
        {%- assign level = item.dir | append: "temp" | replace_first: "/", "" | split: "/" | size | minus: 1 -%}
        {%- capture current -%}
            {%- if page.url == item.url %}current{% endif -%}
        {%- endcapture %}
        {%- if site_lang != lang -%}
            {%- assign level = level | minus: 1 -%}
        {%- endif -%}

        <li class="toctree-l{{ level }} {{ current }}" data-sort="{{ item.sort }}" data-level="{{ level }}">
            <a class="reference internal {{ current }}" href="{{ item.url | relative_url }}">
                {%- if item.sort and site.show_sorted != false -%}
                    {{ item.sort }}. {{ item.title | default: item.url }}
                {%- else -%}
                    {{ item.title | default: item.url }}
                {%- endif -%}
            </a>
        </li>
    {%- endfor -%}

    {% comment %} list dirs {% endcomment %}
    {%- for workdir in workdir_dirs -%}
        {%- assign level = workdir | append: "temp" | replace_first: "/", "" | split: "/" | size | minus: 2 %}
        {%- if site_lang != lang -%}
            {%- assign level = level | minus: 1 -%}
        {%- endif -%}
        <li class="toctree-l{{ level }}">{% include extend/toctree.liquid %}</li>
    {%- endfor -%}
</ul>
